<!doctype html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=robots content="noodp"><meta http-equiv=x-ua-compatible content="IE=edge, chrome=1"><title>Swagger问题汇总 - Yulin Lewis' Blog</title><meta name=keywords content="雨临Lewis,Java,hugo,hexo,博客"><meta name=Description content="不想当写手的码农不是好咸鱼_(xз」∠)_"><meta property="og:title" content="Swagger问题汇总"><meta property="og:description" content="前言
SpringFox是一个开源的用于生成API文档接口的框架，支持多种API文档的格式。可以用SpringFox来整合Spring和Swagger，本文使用的Swagger和SpringFox版本如下：


 1
 2
 3
 4
 5
 6
 7
 8
 9
10


<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger2</artifactId>
  <version>2.9.2</version>
</dependency>
<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger-ui</artifactId>
  <version>2.9.2</version>
</dependency>"><meta property="og:type" content="article"><meta property="og:url" content="https://lewky.cn/posts/swagger-issues/"><meta property="og:image" content="https://lewky.cn/logo.png"><meta property="article:published_time" content="2021-07-09T23:49:08+08:00"><meta property="article:modified_time" content="2021-09-01T23:49:08+08:00"><meta name=twitter:card content="summary_large_image"><meta name=twitter:image content="https://lewky.cn/logo.png"><meta name=twitter:title content="Swagger问题汇总"><meta name=twitter:description content="前言
SpringFox是一个开源的用于生成API文档接口的框架，支持多种API文档的格式。可以用SpringFox来整合Spring和Swagger，本文使用的Swagger和SpringFox版本如下：


 1
 2
 3
 4
 5
 6
 7
 8
 9
10


<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger2</artifactId>
  <version>2.9.2</version>
</dependency>
<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger-ui</artifactId>
  <version>2.9.2</version>
</dependency>"><meta name=application-name content="雨临Lewis的博客"><meta name=apple-mobile-web-app-title content="雨临Lewis的博客"><meta name=theme-color content="#ffffff"><meta name=msapplication-TileColor content="#da532c"><link rel="shortcut icon" type=image/x-icon href=/favicon.ico><link rel=icon type=image/png sizes=32x32 href=/favicon-32x32.png><link rel=icon type=image/png sizes=16x16 href=/favicon-16x16.png><link rel=apple-touch-icon sizes=180x180 href=/apple-touch-icon.png><link rel=mask-icon href=/safari-pinned-tab.svg color=#5bbad5><link rel=manifest href=/site.webmanifest><link rel=canonical href=https://lewky.cn/posts/swagger-issues/><link rel=prev href=https://lewky.cn/posts/java-tree.html/><link rel=next href=https://lewky.cn/posts/maven-issues/><link rel=stylesheet href=https://cdn.jsdelivr.net/npm/normalize.css@8.0.1/normalize.min.css><link rel=stylesheet href=/css/style.min.css><link rel=stylesheet href=https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.13.0/css/all.min.css><link rel=stylesheet href=https://cdn.jsdelivr.net/npm/animate.css@3.7.2/animate.min.css><script type=application/ld+json>{"@context":"http://schema.org","@type":"BlogPosting","headline":"Swagger问题汇总","inLanguage":"","mainEntityOfPage":{"@type":"WebPage","@id":"https:\/\/lewky.cn\/posts\/swagger-issues\/"},"genre":"posts","keywords":"Swagger, SpringFox, 工作记录","wordcount":2775,"url":"https:\/\/lewky.cn\/posts\/swagger-issues\/","datePublished":"2021-07-09T23:49:08+08:00","dateModified":"2021-09-01T23:49:08+08:00","license":"This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.","publisher":{"@type":"Organization","name":"雨临Lewis","logo":"https:\/\/lewky.cn\/images\/avatar.jpg"},"author":{"@type":"Person","name":"雨临Lewis"},"description":""}</script></head><body header-desktop=fixed header-mobile=auto><script type=text/javascript>(window.localStorage&&localStorage.getItem('theme')?localStorage.getItem('theme')==='dark':('auto'==='auto'?window.matchMedia('(prefers-color-scheme: dark)').matches:'auto'==='dark'))&&document.body.setAttribute('theme','dark');</script><div id=mask></div><div class=wrapper><header class=desktop id=header-desktop><div class=header-wrapper><a href=https://github.com/lewky class=github-corner target=_blank title="Follow me on GitHub" aria-label="Follow me on GitHub"><svg width="3.5rem" height="3.5rem" viewBox="0 0 250 250" style="fill:#70b7fd;color:#fff;position:absolute;top:0;border:0;left:0;transform:scale(-1,1)" aria-hidden="true"><path d="M0 0 115 115h15l12 27L250 250V0z"/><path d="M128.3 109C113.8 99.7 119 89.6 119 89.6 122 82.7 120.5 78.6 120.5 78.6 119.2 72 123.4 76.3 123.4 76.3 127.3 80.9 125.5 87.3 125.5 87.3 122.9 97.6 130.6 101.9 134.4 103.2" fill="currentcolor" style="transform-origin:130px 106px" class="octo-arm"/><path d="M115 115C114.9 115.1 118.7 116.5 119.8 115.4L133.7 101.6C136.9 99.2 139.9 98.4 142.2 98.6 133.8 88 127.5 74.4 143.8 58 148.5 53.4 154 51.2 159.7 51 160.3 49.4 163.2 43.6 171.4 40.1 171.4 40.1 176.1 42.5 178.8 56.2 183.1 58.6 187.2 61.8 190.9 65.4 194.5 69 197.7 73.2 200.1 77.6 213.8 80.2 216.3 84.9 216.3 84.9 212.7 93.1 206.9 96 205.4 96.6 205.1 102.4 203 107.8 198.3 112.5 181.9 128.9 168.3 122.5 157.7 114.1 157.9 116.9 156.7 120.9 152.7 124.9L141 136.5C139.8 137.7 141.6 141.9 141.8 141.8z" fill="currentcolor" class="octo-body"/></svg></a><div class=header-title><a href=/ title="Yulin Lewis' Blog"><span class=header-title-pre><i class="fas fa-fw fa-atom"></i></span>雨临Lewis</a></div><div class=menu><div class=menu-inner><div class=dropdown><a href=/posts/ class="menu-item menu-more dropbtn" title=点击查看所有文章><i class="fas fa-fw fa-archive"></i>归档</a><div class="menu-more-content dropdown-content"><a href=/categories/><i class="fas fa-fw fa-th"></i>分类 </a><a href=/tags/><i class="fas fa-fw fa-tag"></i>标签 </a><a href=/hot/ title=文章热度Top15><i class="fas fa-fw fa-fire"></i>热度 </a><a href=/donation/ title=感谢打赏，老板大气~><i class="fas fa-fw fa-donate"></i>打赏 </a><a href=/about/><i class="fas fa-fw fa-at"></i>关于</a></div></div><a class=menu-item href=/friends/ title=欢迎申请友链><i class="fas fa-fw fa-link"></i>友链</a><div class=dropdown><a href=javascript:void(0); class="menu-item menu-more dropbtn" title=一些有意思的东东~><i class="fas fa-fw fa-fan fa-spin"></i>趣味</a><div class="menu-more-content dropdown-content"><a href=/funny/high/ title="前方高能♂ 小心外放！" target=_blank rel=noopener><i class="fas fa-fw fa-dizzy"></i>燥起来！ </a><a href=/funny/mikutap/ title=初音未来音乐游戏 target=_blank rel=noopener><i class="fas fa-fw fa-music"></i>在线打碟 </a><a href=/funny/catch-the-cat/ title=逮住那只猫!><i class="fas fa-fw fa-cat"></i>抓住猫咪</a></div></div><div class=dropdown><a href=/ class="menu-item menu-more dropbtn" title=回到首页><i class="fas fa-fw fa-atom"></i>站点</a><div class="menu-more-content dropdown-content"><a href=/bbs/ title=来留言吧~><i class="fas fa-fw fa-comment"></i>公告留言 </a><a href=https://seo.chinaz.com target=_blank rel=noopener><i class="fas fa-fw fa-chart-line"></i>SEO查询 </a><a href=https://www.ping.cn/http/lewky.cn target=_blank rel=noopener><i class="fas fa-fw fa-bezier-curve"></i>网站测速 </a><a href=/posts/e62c38c4.html/><i class="fas fa-fw fa-cog fa-spin"></i>建站日志</a></div></div><div class=dropdown><a href=javascript:void(0); class="menu-item menu-more dropbtn"><i class="fas fa-fw fa-book"></i>文档</a><div class="menu-more-content dropdown-content"><a href=https://gohugo.io/documentation/ target=_blank rel=noopener><i class="fas fa-fw fa-star"></i>Hugo文档 </a><a href=https://javanote.doc.lewky.cn/ title=尚在完善中~ target=_blank rel=noopener><i class="fab fa-fw fa-java"></i>Java 笔记</a></div></div><a class=menu-item href=/search/ title=渲染搜索结果需要等待几秒钟~><i class="fas fa-fw fa-search"></i>搜索
</a><span class="menu-item delimiter"></span><a href=https://travellings.link target=_blank class=menu-item rel=noopener title=开往-友链接力><i class="fas fa-fw fa-subway"></i></a><a href=https://rssblog.vercel.app/ class=menu-item target=_blank rel=noopener title=RSSBlog><i class="fas fa-fw fa-inbox"></i></a><a href=https://github.com/lewky class=menu-item target=_blank rel=noopener title=GitHub><i class="fab fa-fw fa-github"></i></a></div></div></div></header><header class=mobile id=header-mobile><div class=header-container><div class=header-wrapper><div class=header-title><a href=/ title="Yulin Lewis' Blog"><span class=header-title-pre><i class="fas fa-fw fa-atom"></i></span>雨临Lewis</a></div><div class=menu-toggle id=menu-toggle-mobile><span></span><span></span><span></span></div></div><div class=menu id=menu-mobile><div class=dropdown><a href=/posts/ class="menu-item menu-more dropbtn" title=点击查看所有文章><i class="fas fa-fw fa-archive"></i>归档</a><div class="menu-more-content dropdown-content"><a href=/categories/><i class="fas fa-fw fa-th"></i>分类 </a><a href=/tags/><i class="fas fa-fw fa-tag"></i>标签 </a><a href=/hot/ title=文章热度Top15><i class="fas fa-fw fa-fire"></i>热度 </a><a href=/donation/ title=感谢打赏，老板大气~><i class="fas fa-fw fa-donate"></i>打赏 </a><a href=/about/><i class="fas fa-fw fa-at"></i>关于</a></div></div><a class=menu-item href=/friends/ title=欢迎申请友链><i class="fas fa-fw fa-link"></i>友链</a><div class=dropdown><a href=javascript:void(0); class="menu-item menu-more dropbtn" title=一些有意思的东东~><i class="fas fa-fw fa-fan fa-spin"></i>趣味</a><div class="menu-more-content dropdown-content"><a href=/funny/high/ title="前方高能♂ 小心外放！" target=_blank rel=noopener><i class="fas fa-fw fa-dizzy"></i>燥起来！ </a><a href=/funny/mikutap/ title=初音未来音乐游戏 target=_blank rel=noopener><i class="fas fa-fw fa-music"></i>在线打碟 </a><a href=/funny/catch-the-cat/ title=逮住那只猫!><i class="fas fa-fw fa-cat"></i>抓住猫咪</a></div></div><div class=dropdown><a href=/ class="menu-item menu-more dropbtn" title=回到首页><i class="fas fa-fw fa-atom"></i>站点</a><div class="menu-more-content dropdown-content"><a href=/bbs/ title=来留言吧~><i class="fas fa-fw fa-comment"></i>公告留言 </a><a href=https://seo.chinaz.com target=_blank rel=noopener><i class="fas fa-fw fa-chart-line"></i>SEO查询 </a><a href=https://www.ping.cn/http/lewky.cn target=_blank rel=noopener><i class="fas fa-fw fa-bezier-curve"></i>网站测速 </a><a href=/posts/e62c38c4.html/><i class="fas fa-fw fa-cog fa-spin"></i>建站日志</a></div></div><div class=dropdown><a href=javascript:void(0); class="menu-item menu-more dropbtn"><i class="fas fa-fw fa-book"></i>文档</a><div class="menu-more-content dropdown-content"><a href=https://gohugo.io/documentation/ target=_blank rel=noopener><i class="fas fa-fw fa-star"></i>Hugo文档 </a><a href=https://javanote.doc.lewky.cn/ title=尚在完善中~ target=_blank rel=noopener><i class="fab fa-fw fa-java"></i>Java 笔记</a></div></div><a class=menu-item href=/search/ title=渲染搜索结果需要等待几秒钟~><i class="fas fa-fw fa-search"></i>搜索</a>
<a href=https://travellings.link target=_blank class=menu-item rel=noopener title=开往-友链接力><i class="fas fa-fw fa-subway"></i></a><a href=https://rssblog.vercel.app/ class=menu-item target=_blank rel=noopener title=RSSBlog><i class="fas fa-fw fa-inbox"></i></a><a href=https://github.com/lewky class=menu-item target=_blank rel=noopener title=GitHub><i class="fab fa-fw fa-github"></i></a></div></div></header><div class="search-dropdown desktop"><div id=search-dropdown-desktop></div></div><div class="search-dropdown mobile"><div id=search-dropdown-mobile></div></div><main class=main><div class=container><div class=toc id=toc-auto><h2 class=toc-title>目录</h2><div class=toc-content id=toc-content-auto></div></div><article class="page single"><h1 class="single-title animated flipInX">Swagger问题汇总</h1><div class=post-meta><div class=post-meta-line><span class=post-author><a href=/ title=Author rel=author class=author><i class="fas fa-user-circle fa-fw"></i>雨临Lewis</a></span>&nbsp;<span class=post-category>收录于 <a href=/categories/%E5%B7%A5%E4%BD%9C%E8%AE%B0%E5%BD%95/><i class="far fa-folder fa-fw"></i>工作记录</a></span></div><div class=post-meta-line><i class="far fa-calendar fa-fw"></i>&nbsp;<time datetime=2021-07-09>2021-07-09</time>&nbsp;<i class="far fa-calendar-plus fa-fw"></i>&nbsp;<time datetime=2021-09-01>2021-09-01</time>&nbsp;<i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 2775 字
<i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 6 分钟&nbsp;<span id=/posts/swagger-issues/ class=leancloud_visitors data-flag-title=Swagger问题汇总>
<i class="far fa-eye fa-fw"></i>&nbsp;<span class=leancloud-visitors-count></span>&nbsp;次阅读
</span>&nbsp;
<a href=#comments id=post-meta-vcount title=查看评论><i class="fas fa-comment fa-fw"></i>&nbsp;<span id=/posts/swagger-issues/ class=waline-comment-count></span>&nbsp;条评论</a></div></div><div class="details toc" id=toc-static kept><div class="details-summary toc-title"><span>目录</span>
<span><i class="details-icon fas fa-angle-right"></i></span></div><div class="details-content toc-content" id=toc-content-static><nav id=TableOfContents><ol><li><a href=#前言>前言</a></li><li><a href=#隐藏指定的接口>隐藏指定的接口</a><ol><li><a href=#使用apiignore>使用<code>@ApiIgnore</code></a></li><li><a href=#使用springfox提供的docket类的paths来定制>使用SpringFox提供的Docket类的<code>paths()</code>来定制</a></li></ol></li><li><a href=#定义response中model的map字段显示>定义Response中Model的map字段显示</a></li><li><a href=#按类中字段定义的顺序展示字段>按类中字段定义的顺序展示字段</a></li><li><a href=#参考链接>参考链接</a></li></ol></nav></div></div><div class=content id=content><h2 id=前言>前言</h2><p>SpringFox是一个开源的用于生成API文档接口的框架，支持多种API文档的格式。可以用SpringFox来整合Spring和Swagger，本文使用的Swagger和SpringFox版本如下：</p><div class=highlight><div class=chroma><table class=lntable><tr><td class=lntd><pre class=chroma><code><span class=lnt> 1
</span><span class=lnt> 2
</span><span class=lnt> 3
</span><span class=lnt> 4
</span><span class=lnt> 5
</span><span class=lnt> 6
</span><span class=lnt> 7
</span><span class=lnt> 8
</span><span class=lnt> 9
</span><span class=lnt>10
</span></code></pre></td><td class=lntd><pre class=chroma><code class=language-java data-lang=java><span class=o>&lt;</span><span class=n>dependency</span><span class=o>&gt;</span>
  <span class=o>&lt;</span><span class=n>groupId</span><span class=o>&gt;</span><span class=n>io</span><span class=o>.</span><span class=na>springfox</span><span class=o>&lt;/</span><span class=n>groupId</span><span class=o>&gt;</span>
  <span class=o>&lt;</span><span class=n>artifactId</span><span class=o>&gt;</span><span class=n>springfox</span><span class=o>-</span><span class=n>swagger2</span><span class=o>&lt;/</span><span class=n>artifactId</span><span class=o>&gt;</span>
  <span class=o>&lt;</span><span class=n>version</span><span class=o>&gt;</span><span class=n>2</span><span class=o>.</span><span class=na>9</span><span class=o>.</span><span class=na>2</span><span class=o>&lt;/</span><span class=n>version</span><span class=o>&gt;</span>
<span class=o>&lt;/</span><span class=n>dependency</span><span class=o>&gt;</span>
<span class=o>&lt;</span><span class=n>dependency</span><span class=o>&gt;</span>
  <span class=o>&lt;</span><span class=n>groupId</span><span class=o>&gt;</span><span class=n>io</span><span class=o>.</span><span class=na>springfox</span><span class=o>&lt;/</span><span class=n>groupId</span><span class=o>&gt;</span>
  <span class=o>&lt;</span><span class=n>artifactId</span><span class=o>&gt;</span><span class=n>springfox</span><span class=o>-</span><span class=n>swagger</span><span class=o>-</span><span class=n>ui</span><span class=o>&lt;/</span><span class=n>artifactId</span><span class=o>&gt;</span>
  <span class=o>&lt;</span><span class=n>version</span><span class=o>&gt;</span><span class=n>2</span><span class=o>.</span><span class=na>9</span><span class=o>.</span><span class=na>2</span><span class=o>&lt;/</span><span class=n>version</span><span class=o>&gt;</span>
<span class=o>&lt;/</span><span class=n>dependency</span><span class=o>&gt;</span>
</code></pre></td></tr></table></div></div><h2 id=隐藏指定的接口>隐藏指定的接口</h2><h3 id=使用apiignore>使用<code>@ApiIgnore</code></h3><p>在想要隐藏的方法上添加<code>@ApiIgnore</code>注解即可，该注解还可以添加在类上和方法参数上。</p><h3 id=使用springfox提供的docket类的paths来定制>使用SpringFox提供的Docket类的<code>paths()</code>来定制</h3><p><code>paths()</code>支持两种表达式，一种是Java的正则表达式，一种是Spring框架的Ant表达式。</p><p>通过Docket类的链式调用来实现：<code>new Docket().select().apis().paths().build()</code>。</p><div class=highlight><div class=chroma><table class=lntable><tr><td class=lntd><pre class=chroma><code><span class=lnt> 1
</span><span class=lnt> 2
</span><span class=lnt> 3
</span><span class=lnt> 4
</span><span class=lnt> 5
</span><span class=lnt> 6
</span><span class=lnt> 7
</span><span class=lnt> 8
</span><span class=lnt> 9
</span><span class=lnt>10
</span><span class=lnt>11
</span><span class=lnt>12
</span><span class=lnt>13
</span><span class=lnt>14
</span><span class=lnt>15
</span><span class=lnt>16
</span><span class=lnt>17
</span><span class=lnt>18
</span><span class=lnt>19
</span><span class=lnt>20
</span><span class=lnt>21
</span><span class=lnt>22
</span><span class=lnt>23
</span><span class=lnt>24
</span><span class=lnt>25
</span><span class=lnt>26
</span><span class=lnt>27
</span><span class=lnt>28
</span><span class=lnt>29
</span><span class=lnt>30
</span><span class=lnt>31
</span><span class=lnt>32
</span><span class=lnt>33
</span><span class=lnt>34
</span><span class=lnt>35
</span><span class=lnt>36
</span><span class=lnt>37
</span><span class=lnt>38
</span><span class=lnt>39
</span><span class=lnt>40
</span><span class=lnt>41
</span><span class=lnt>42
</span><span class=lnt>43
</span></code></pre></td><td class=lntd><pre class=chroma><code class=language-java data-lang=java><span class=nd>@Bean</span>
<span class=kd>public</span> <span class=n>Docket</span> <span class=nf>api</span><span class=o>()</span> <span class=o>{</span>
    <span class=k>return</span> <span class=k>new</span> <span class=n>Docket</span><span class=o>(</span><span class=n>DocumentationType</span><span class=o>.</span><span class=na>SWAGGER_2</span><span class=o>)</span>
        <span class=o>.</span><span class=na>groupName</span><span class=o>(</span><span class=s>&#34;api&#34;</span><span class=o>)</span>
        <span class=o>.</span><span class=na>apiInfo</span><span class=o>(</span><span class=n>metaData</span><span class=o>())</span>
        <span class=o>.</span><span class=na>ignoredParameterTypes</span><span class=o>(</span><span class=n>Authentication</span><span class=o>.</span><span class=na>class</span><span class=o>)</span>
        <span class=o>.</span><span class=na>select</span><span class=o>()</span>
        <span class=o>.</span><span class=na>apis</span><span class=o>(</span><span class=n>RequestHandlerSelectors</span><span class=o>.</span><span class=na>basePackage</span><span class=o>(</span><span class=s>&#34;com.test&#34;</span><span class=o>))</span>
        <span class=o>.</span><span class=na>paths</span><span class=o>(</span><span class=n>PathSelectors</span><span class=o>.</span><span class=na>regex</span><span class=o>(</span><span class=s>&#34;/api/.*&#34;</span><span class=o>))</span>
        <span class=o>.</span><span class=na>build</span><span class=o>()</span>
        <span class=o>.</span><span class=na>securitySchemes</span><span class=o>(</span><span class=n>Collections</span><span class=o>.</span><span class=na>singletonList</span><span class=o>(</span><span class=n>securitySchema</span><span class=o>()))</span>
        <span class=o>.</span><span class=na>securityContexts</span><span class=o>(</span><span class=n>Collections</span><span class=o>.</span><span class=na>singletonList</span><span class=o>(</span><span class=n>securityContext</span><span class=o>()));</span>
<span class=o>}</span>

<span class=kd>private</span> <span class=n>ApiInfo</span> <span class=nf>metaData</span><span class=o>()</span> <span class=o>{</span>
    <span class=k>return</span> <span class=k>new</span> <span class=n>ApiInfoBuilder</span><span class=o>()</span>
        <span class=o>.</span><span class=na>title</span><span class=o>(</span><span class=s>&#34;Test API&#34;</span><span class=o>)</span>
        <span class=o>.</span><span class=na>description</span><span class=o>(</span><span class=s>&#34;Test Application&#34;</span><span class=o>)</span>
        <span class=o>.</span><span class=na>version</span><span class=o>(</span><span class=s>&#34;0.0.1&#34;</span><span class=o>)</span>
        <span class=o>.</span><span class=na>contact</span><span class=o>(</span><span class=k>new</span> <span class=n>Contact</span><span class=o>(</span><span class=s>&#34;Lewky&#34;</span><span class=o>,</span> <span class=s>&#34;lewky.cn&#34;</span><span class=o>,</span> <span class=s>&#34;lewky@test.com&#34;</span><span class=o>))</span>
        <span class=o>.</span><span class=na>build</span><span class=o>();</span>
<span class=o>}</span>

<span class=kd>private</span> <span class=n>OAuth</span> <span class=nf>securitySchema</span><span class=o>()</span> <span class=o>{</span>
    <span class=kd>final</span> <span class=n>List</span><span class=o>&lt;</span><span class=n>AuthorizationScope</span><span class=o>&gt;</span> <span class=n>authorizationScopeList</span> <span class=o>=</span> <span class=k>new</span> <span class=n>ArrayList</span><span class=o>&lt;&gt;();</span>
    <span class=n>authorizationScopeList</span><span class=o>.</span><span class=na>add</span><span class=o>(</span><span class=k>new</span> <span class=n>AuthorizationScope</span><span class=o>(</span><span class=s>&#34;read&#34;</span><span class=o>,</span> <span class=s>&#34;read all&#34;</span><span class=o>));</span>
    <span class=n>authorizationScopeList</span><span class=o>.</span><span class=na>add</span><span class=o>(</span><span class=k>new</span> <span class=n>AuthorizationScope</span><span class=o>(</span><span class=s>&#34;trust&#34;</span><span class=o>,</span> <span class=s>&#34;trust all&#34;</span><span class=o>));</span>
    <span class=n>authorizationScopeList</span><span class=o>.</span><span class=na>add</span><span class=o>(</span><span class=k>new</span> <span class=n>AuthorizationScope</span><span class=o>(</span><span class=s>&#34;write&#34;</span><span class=o>,</span> <span class=s>&#34;access all&#34;</span><span class=o>));</span>

    <span class=kd>final</span> <span class=n>List</span><span class=o>&lt;</span><span class=n>GrantType</span><span class=o>&gt;</span> <span class=n>grantTypes</span> <span class=o>=</span> <span class=k>new</span> <span class=n>ArrayList</span><span class=o>&lt;&gt;();</span>
    <span class=kd>final</span> <span class=n>GrantType</span> <span class=n>creGrant</span> <span class=o>=</span> <span class=k>new</span> <span class=n>ResourceOwnerPasswordCredentialsGrant</span><span class=o>(</span><span class=s>&#34;/oauth/token&#34;</span><span class=o>);</span>

    <span class=n>grantTypes</span><span class=o>.</span><span class=na>add</span><span class=o>(</span><span class=n>creGrant</span><span class=o>);</span>

    <span class=k>return</span> <span class=k>new</span> <span class=n>OAuth</span><span class=o>(</span><span class=s>&#34;oauth2schema&#34;</span><span class=o>,</span> <span class=n>authorizationScopeList</span><span class=o>,</span> <span class=n>grantTypes</span><span class=o>);</span>
<span class=o>}</span>


<span class=kd>private</span> <span class=n>SecurityContext</span> <span class=nf>securityContext</span><span class=o>()</span> <span class=o>{</span>
    <span class=k>return</span> <span class=n>SecurityContext</span><span class=o>.</span><span class=na>builder</span><span class=o>()</span>
        <span class=o>.</span><span class=na>securityReferences</span><span class=o>(</span><span class=n>defaultAuth</span><span class=o>()).</span><span class=na>forPaths</span><span class=o>(</span><span class=n>PathSelectors</span><span class=o>.</span><span class=na>ant</span><span class=o>(</span><span class=s>&#34;/api/**&#34;</span><span class=o>))</span>
        <span class=o>.</span><span class=na>build</span><span class=o>();</span>
<span class=o>}</span>
</code></pre></td></tr></table></div></div><p>下面是ant表达式的写法，用的是<code>AntPathMatcher</code>来匹配文档路径：</p><ul><li><code>?</code>匹配一个字符</li><li><code>*</code>匹配0个或多个字符</li><li><code>**</code>匹配0个或多个目录</li></ul><div class=highlight><div class=chroma><table class=lntable><tr><td class=lntd><pre class=chroma><code><span class=lnt> 1
</span><span class=lnt> 2
</span><span class=lnt> 3
</span><span class=lnt> 4
</span><span class=lnt> 5
</span><span class=lnt> 6
</span><span class=lnt> 7
</span><span class=lnt> 8
</span><span class=lnt> 9
</span><span class=lnt>10
</span><span class=lnt>11
</span><span class=lnt>12
</span><span class=lnt>13
</span></code></pre></td><td class=lntd><pre class=chroma><code class=language-java data-lang=java><span class=nd>@Bean</span>
<span class=kd>public</span> <span class=n>Docket</span> <span class=nf>oauthApi</span><span class=o>()</span> <span class=o>{</span>
    <span class=k>return</span> <span class=k>new</span> <span class=n>Docket</span><span class=o>(</span><span class=n>DocumentationType</span><span class=o>.</span><span class=na>SWAGGER_2</span><span class=o>)</span>
        <span class=o>.</span><span class=na>groupName</span><span class=o>(</span><span class=s>&#34;oauth&#34;</span><span class=o>)</span>
        <span class=o>.</span><span class=na>apiInfo</span><span class=o>(</span><span class=n>metaData</span><span class=o>())</span>
        <span class=o>.</span><span class=na>ignoredParameterTypes</span><span class=o>(</span><span class=n>Authentication</span><span class=o>.</span><span class=na>class</span><span class=o>)</span>
        <span class=o>.</span><span class=na>select</span><span class=o>()</span>
        <span class=o>.</span><span class=na>apis</span><span class=o>(</span><span class=n>RequestHandlerSelectors</span><span class=o>.</span><span class=na>any</span><span class=o>())</span>
        <span class=o>.</span><span class=na>paths</span><span class=o>(</span><span class=n>PathSelectors</span><span class=o>.</span><span class=na>ant</span><span class=o>(</span><span class=s>&#34;/oauth/**&#34;</span><span class=o>))</span>
        <span class=o>.</span><span class=na>build</span><span class=o>()</span>
        <span class=o>.</span><span class=na>securitySchemes</span><span class=o>(</span><span class=n>Collections</span><span class=o>.</span><span class=na>singletonList</span><span class=o>(</span><span class=n>securitySchema</span><span class=o>()))</span>
        <span class=o>.</span><span class=na>securityContexts</span><span class=o>(</span><span class=n>Collections</span><span class=o>.</span><span class=na>singletonList</span><span class=o>(</span><span class=n>securityContext</span><span class=o>()));</span>
<span class=o>}</span>
</code></pre></td></tr></table></div></div><h2 id=定义response中model的map字段显示>定义Response中Model的map字段显示</h2><p>Swagger2在显示一个接口的Response时，如果Model中存在map类型的字段（比如下面的<code>customFields</code>），则会在<code>Example Value</code>中显示为：</p><div class=highlight><div class=chroma><table class=lntable><tr><td class=lntd><pre class=chroma><code><span class=lnt>1
</span><span class=lnt>2
</span><span class=lnt>3
</span><span class=lnt>4
</span><span class=lnt>5
</span></code></pre></td><td class=lntd><pre class=chroma><code class=language-java data-lang=java><span class=s>&#34;customFields&#34;</span><span class=o>:</span> <span class=o>{</span>
  <span class=s>&#34;additionalProp1&#34;</span><span class=o>:</span> <span class=o>{},</span>
  <span class=s>&#34;additionalProp2&#34;</span><span class=o>:</span> <span class=o>{},</span>
  <span class=s>&#34;additionalProp3&#34;</span><span class=o>:</span> <span class=o>{}</span>
<span class=o>}</span>
</code></pre></td></tr></table></div></div><p>这个map里的字段是动态生成的，如果想要显示成对应的字段，需要实现<code>ModelPropertyBuilderPlugin</code>接口，然后重写<code>supports()</code>和<code>apply()</code>这两个方法，可以参考框架提供的实现类<code>ApiModelPropertyPropertyBuilder</code>来写。</p><p>对于自定义的类，需要注意的是注入的顺序，需要在框架的默认实现类之后注入。可以使用<code>@Order</code>来控制注入顺序，默认是最低优先级的注入顺序。</p><p>功能需求：map对象的字段是由Hibernate的hbm.xml配置的动态table，需要读取这个xml里的字段，然后将其转为对应的pojo中的字段。</p><p>Map对象的字段重写的具体思路如下：</p><ul><li>在map字段上添加<code>@ApiModelProperty(notes = "xxx")</code>。使用<code>notes</code>属性的原因是，该字段被Swagger废弃了，这里用来实现自定义的功能就不会与原框架的功能产生冲突。</li><li>读取注解中notes的值，解析Hibernate的hbm.xml，根据notes值找到对应的结点并解析。</li><li>将解析得到的结点用javassist生成一个类，同一个类生成一次即可，别反复生成，浪费性能。</li><li>将生成的类作为当前map字段的解析类型，swagger是用的fasterxml来将pojo转化为json的。</li></ul><div class=highlight><div class=chroma><table class=lntable><tr><td class=lntd><pre class=chroma><code><span class=lnt>  1
</span><span class=lnt>  2
</span><span class=lnt>  3
</span><span class=lnt>  4
</span><span class=lnt>  5
</span><span class=lnt>  6
</span><span class=lnt>  7
</span><span class=lnt>  8
</span><span class=lnt>  9
</span><span class=lnt> 10
</span><span class=lnt> 11
</span><span class=lnt> 12
</span><span class=lnt> 13
</span><span class=lnt> 14
</span><span class=lnt> 15
</span><span class=lnt> 16
</span><span class=lnt> 17
</span><span class=lnt> 18
</span><span class=lnt> 19
</span><span class=lnt> 20
</span><span class=lnt> 21
</span><span class=lnt> 22
</span><span class=lnt> 23
</span><span class=lnt> 24
</span><span class=lnt> 25
</span><span class=lnt> 26
</span><span class=lnt> 27
</span><span class=lnt> 28
</span><span class=lnt> 29
</span><span class=lnt> 30
</span><span class=lnt> 31
</span><span class=lnt> 32
</span><span class=lnt> 33
</span><span class=lnt> 34
</span><span class=lnt> 35
</span><span class=lnt> 36
</span><span class=lnt> 37
</span><span class=lnt> 38
</span><span class=lnt> 39
</span><span class=lnt> 40
</span><span class=lnt> 41
</span><span class=lnt> 42
</span><span class=lnt> 43
</span><span class=lnt> 44
</span><span class=lnt> 45
</span><span class=lnt> 46
</span><span class=lnt> 47
</span><span class=lnt> 48
</span><span class=lnt> 49
</span><span class=lnt> 50
</span><span class=lnt> 51
</span><span class=lnt> 52
</span><span class=lnt> 53
</span><span class=lnt> 54
</span><span class=lnt> 55
</span><span class=lnt> 56
</span><span class=lnt> 57
</span><span class=lnt> 58
</span><span class=lnt> 59
</span><span class=lnt> 60
</span><span class=lnt> 61
</span><span class=lnt> 62
</span><span class=lnt> 63
</span><span class=lnt> 64
</span><span class=lnt> 65
</span><span class=lnt> 66
</span><span class=lnt> 67
</span><span class=lnt> 68
</span><span class=lnt> 69
</span><span class=lnt> 70
</span><span class=lnt> 71
</span><span class=lnt> 72
</span><span class=lnt> 73
</span><span class=lnt> 74
</span><span class=lnt> 75
</span><span class=lnt> 76
</span><span class=lnt> 77
</span><span class=lnt> 78
</span><span class=lnt> 79
</span><span class=lnt> 80
</span><span class=lnt> 81
</span><span class=lnt> 82
</span><span class=lnt> 83
</span><span class=lnt> 84
</span><span class=lnt> 85
</span><span class=lnt> 86
</span><span class=lnt> 87
</span><span class=lnt> 88
</span><span class=lnt> 89
</span><span class=lnt> 90
</span><span class=lnt> 91
</span><span class=lnt> 92
</span><span class=lnt> 93
</span><span class=lnt> 94
</span><span class=lnt> 95
</span><span class=lnt> 96
</span><span class=lnt> 97
</span><span class=lnt> 98
</span><span class=lnt> 99
</span><span class=lnt>100
</span><span class=lnt>101
</span><span class=lnt>102
</span><span class=lnt>103
</span><span class=lnt>104
</span><span class=lnt>105
</span><span class=lnt>106
</span><span class=lnt>107
</span><span class=lnt>108
</span><span class=lnt>109
</span><span class=lnt>110
</span><span class=lnt>111
</span><span class=lnt>112
</span><span class=lnt>113
</span><span class=lnt>114
</span><span class=lnt>115
</span><span class=lnt>116
</span><span class=lnt>117
</span><span class=lnt>118
</span><span class=lnt>119
</span><span class=lnt>120
</span><span class=lnt>121
</span><span class=lnt>122
</span><span class=lnt>123
</span><span class=lnt>124
</span><span class=lnt>125
</span><span class=lnt>126
</span><span class=lnt>127
</span><span class=lnt>128
</span><span class=lnt>129
</span><span class=lnt>130
</span><span class=lnt>131
</span><span class=lnt>132
</span><span class=lnt>133
</span><span class=lnt>134
</span><span class=lnt>135
</span><span class=lnt>136
</span><span class=lnt>137
</span><span class=lnt>138
</span><span class=lnt>139
</span><span class=lnt>140
</span><span class=lnt>141
</span><span class=lnt>142
</span><span class=lnt>143
</span><span class=lnt>144
</span><span class=lnt>145
</span><span class=lnt>146
</span><span class=lnt>147
</span><span class=lnt>148
</span><span class=lnt>149
</span><span class=lnt>150
</span><span class=lnt>151
</span><span class=lnt>152
</span><span class=lnt>153
</span><span class=lnt>154
</span><span class=lnt>155
</span><span class=lnt>156
</span><span class=lnt>157
</span><span class=lnt>158
</span><span class=lnt>159
</span><span class=lnt>160
</span><span class=lnt>161
</span><span class=lnt>162
</span><span class=lnt>163
</span><span class=lnt>164
</span><span class=lnt>165
</span><span class=lnt>166
</span><span class=lnt>167
</span></code></pre></td><td class=lntd><pre class=chroma><code class=language-java data-lang=java><span class=nd>@Component</span>
<span class=nd>@Order</span>
<span class=nd>@Slf4j</span>
<span class=kd>public</span> <span class=kd>class</span> <span class=nc>HashMapModelPropertyBuilder</span> <span class=kd>implements</span> <span class=n>ModelPropertyBuilderPlugin</span> <span class=o>{</span>
    <span class=nd>@Autowired</span>
    <span class=kd>private</span> <span class=n>TypeResolver</span> <span class=n>typeResolver</span><span class=o>;</span>

    <span class=nd>@Override</span>
    <span class=kd>public</span> <span class=kt>boolean</span> <span class=nf>supports</span><span class=o>(</span><span class=kd>final</span> <span class=n>DocumentationType</span> <span class=n>delimiter</span><span class=o>)</span> <span class=o>{</span>
        <span class=k>return</span> <span class=kc>true</span><span class=o>;</span>
    <span class=o>}</span>

    <span class=nd>@Override</span>
    <span class=kd>public</span> <span class=kt>void</span> <span class=nf>apply</span><span class=o>(</span><span class=kd>final</span> <span class=n>ModelPropertyContext</span> <span class=n>context</span><span class=o>)</span> <span class=o>{</span>
        <span class=n>Optional</span><span class=o>&lt;</span><span class=n>ApiModelProperty</span><span class=o>&gt;</span> <span class=n>annotation</span> <span class=o>=</span> <span class=n>Optional</span><span class=o>.</span><span class=na>absent</span><span class=o>();</span>

        <span class=k>if</span> <span class=o>(</span><span class=n>context</span><span class=o>.</span><span class=na>getAnnotatedElement</span><span class=o>().</span><span class=na>isPresent</span><span class=o>())</span> <span class=o>{</span>
          <span class=n>annotation</span> <span class=o>=</span> <span class=n>annotation</span><span class=o>.</span><span class=na>or</span><span class=o>(</span><span class=n>findApiModePropertyAnnotation</span><span class=o>(</span><span class=n>context</span><span class=o>.</span><span class=na>getAnnotatedElement</span><span class=o>().</span><span class=na>get</span><span class=o>()));</span>
        <span class=o>}</span>
        <span class=k>if</span> <span class=o>(</span><span class=n>context</span><span class=o>.</span><span class=na>getBeanPropertyDefinition</span><span class=o>().</span><span class=na>isPresent</span><span class=o>())</span> <span class=o>{</span>
          <span class=n>annotation</span> <span class=o>=</span> <span class=n>annotation</span><span class=o>.</span><span class=na>or</span><span class=o>(</span><span class=n>findPropertyAnnotation</span><span class=o>(</span>
              <span class=n>context</span><span class=o>.</span><span class=na>getBeanPropertyDefinition</span><span class=o>().</span><span class=na>get</span><span class=o>(),</span>
              <span class=n>ApiModelProperty</span><span class=o>.</span><span class=na>class</span><span class=o>));</span>
        <span class=o>}</span>

		<span class=c1>// 只有在map类型的字段上使用了ApiModelProperty注解，并使用了notes属性才进行字段的解析
</span><span class=c1></span>        <span class=k>if</span> <span class=o>(</span><span class=n>annotation</span><span class=o>.</span><span class=na>isPresent</span><span class=o>()</span> <span class=o>&amp;&amp;</span> <span class=n>context</span><span class=o>.</span><span class=na>getBeanPropertyDefinition</span><span class=o>().</span><span class=na>isPresent</span><span class=o>())</span> <span class=o>{</span>
            <span class=kd>final</span> <span class=n>String</span> <span class=n>tableName</span> <span class=o>=</span> <span class=n>annotation</span><span class=o>.</span><span class=na>get</span><span class=o>().</span><span class=na>notes</span><span class=o>();</span>
            <span class=k>if</span> <span class=o>(</span><span class=n>StringUtils</span><span class=o>.</span><span class=na>isBlank</span><span class=o>(</span><span class=n>applyToEntity</span><span class=o>))</span> <span class=o>{</span>
                <span class=k>return</span><span class=o>;</span>
            <span class=o>}</span>

            <span class=kd>final</span> <span class=n>BeanPropertyDefinition</span> <span class=n>beanPropertyDefinition</span> <span class=o>=</span> <span class=n>context</span><span class=o>.</span><span class=na>getBeanPropertyDefinition</span><span class=o>().</span><span class=na>get</span><span class=o>();</span>
            <span class=k>if</span> <span class=o>(!</span><span class=n>HashMap</span><span class=o>.</span><span class=na>class</span><span class=o>.</span><span class=na>equals</span><span class=o>(</span><span class=n>beanPropertyDefinition</span><span class=o>.</span><span class=na>getField</span><span class=o>().</span><span class=na>getRawType</span><span class=o>()))</span> <span class=o>{</span>
                <span class=k>return</span><span class=o>;</span>
            <span class=o>}</span>

			<span class=c1>// 最关键的功能实现：解析xml并生成对应的类，再设置为当前的Map字段的解析类型
</span><span class=c1></span>            <span class=n>context</span><span class=o>.</span><span class=na>getBuilder</span><span class=o>().</span><span class=na>type</span><span class=o>(</span><span class=n>typeResolver</span><span class=o>.</span><span class=na>resolve</span><span class=o>(</span><span class=n>createRefModel</span><span class=o>(</span><span class=n>tableName</span><span class=o>)));</span>
        <span class=o>}</span>
    <span class=o>}</span>

    <span class=c1>// Dynamic generated class package prefix for HashMap model.
</span><span class=c1></span>    <span class=kd>private</span> <span class=kd>final</span> <span class=kd>static</span> <span class=n>String</span> <span class=n>BASE_PACKAGE_RPEFIX</span> <span class=o>=</span> <span class=s>&#34;com.test.swagger.model.&#34;</span><span class=o>;</span>

    <span class=kd>private</span> <span class=n>Class</span> <span class=nf>createRefModel</span><span class=o>(</span><span class=kd>final</span> <span class=n>String</span> <span class=n>name</span><span class=o>)</span> <span class=o>{</span>
        <span class=kd>final</span> <span class=n>ClassPool</span> <span class=n>pool</span> <span class=o>=</span> <span class=n>ClassPool</span><span class=o>.</span><span class=na>getDefault</span><span class=o>();</span>
        <span class=kd>final</span> <span class=n>String</span> <span class=n>className</span> <span class=o>=</span> <span class=n>BASE_PACKAGE_RPEFIX</span> <span class=o>+</span> <span class=n>name</span><span class=o>;</span>
        <span class=n>CtClass</span> <span class=n>ctClass</span> <span class=o>=</span> <span class=n>pool</span><span class=o>.</span><span class=na>getOrNull</span><span class=o>(</span><span class=n>className</span><span class=o>);</span>
        <span class=n>Class</span> <span class=n>result</span> <span class=o>=</span> <span class=kc>null</span><span class=o>;</span>

        <span class=k>if</span> <span class=o>(</span><span class=n>ctClass</span> <span class=o>==</span> <span class=kc>null</span><span class=o>)</span> <span class=o>{</span>
            <span class=c1>// Create new public class.
</span><span class=c1></span>            <span class=n>ctClass</span> <span class=o>=</span> <span class=n>pool</span><span class=o>.</span><span class=na>makeClass</span><span class=o>(</span><span class=n>BASE_PACKAGE_RPEFIX</span> <span class=o>+</span> <span class=n>name</span><span class=o>);</span>
            <span class=n>ctClass</span> <span class=o>=</span> <span class=n>loadCustomTableHbmXml</span><span class=o>(</span><span class=n>name</span><span class=o>,</span> <span class=n>ctClass</span><span class=o>);</span>
            <span class=k>try</span> <span class=o>{</span>
                <span class=n>result</span> <span class=o>=</span> <span class=n>ctClass</span><span class=o>.</span><span class=na>toClass</span><span class=o>();</span>
            <span class=o>}</span> <span class=k>catch</span> <span class=o>(</span><span class=kd>final</span> <span class=n>CannotCompileException</span> <span class=n>e</span><span class=o>)</span> <span class=o>{</span>
                <span class=n>log</span><span class=o>.</span><span class=na>error</span><span class=o>(</span><span class=s>&#34;Cannot create ref model.&#34;</span><span class=o>,</span> <span class=n>e</span><span class=o>);</span>
            <span class=o>}</span>
        <span class=o>}</span> <span class=k>else</span> <span class=o>{</span>
            <span class=k>try</span> <span class=o>{</span>
                <span class=n>result</span> <span class=o>=</span> <span class=n>Class</span><span class=o>.</span><span class=na>forName</span><span class=o>(</span><span class=n>className</span><span class=o>);</span>
            <span class=o>}</span> <span class=k>catch</span> <span class=o>(</span><span class=kd>final</span> <span class=n>ClassNotFoundException</span> <span class=n>e</span><span class=o>)</span> <span class=o>{</span>
                <span class=n>log</span><span class=o>.</span><span class=na>error</span><span class=o>(</span><span class=s>&#34;Cannot load Class: {}.&#34;</span><span class=o>,</span> <span class=n>className</span><span class=o>,</span> <span class=n>e</span><span class=o>);</span>
            <span class=o>}</span>
        <span class=o>}</span>

        <span class=k>return</span> <span class=n>result</span><span class=o>;</span>
    <span class=o>}</span>

    <span class=kd>private</span> <span class=n>CtClass</span> <span class=nf>loadCustomTableHbmXml</span><span class=o>(</span><span class=kd>final</span> <span class=n>String</span> <span class=n>entityName</span><span class=o>,</span> <span class=kd>final</span> <span class=n>CtClass</span> <span class=n>ctClass</span><span class=o>)</span> <span class=o>{</span>
		<span class=c1>// 解析hbm.xml
</span><span class=c1></span>        <span class=kd>final</span> <span class=n>Resource</span> <span class=n>resource</span> <span class=o>=</span> <span class=k>new</span> <span class=n>ClassPathResource</span><span class=o>(</span><span class=s>&#34;hibernate/CustomTable.hbm.xml&#34;</span><span class=o>);</span>
        <span class=kd>final</span> <span class=n>SAXReader</span> <span class=n>saxReader</span> <span class=o>=</span> <span class=k>new</span> <span class=n>SAXReader</span><span class=o>();</span>
        <span class=n>Document</span> <span class=n>doc</span> <span class=o>=</span> <span class=kc>null</span><span class=o>;</span>
        <span class=k>try</span> <span class=o>{</span>
            <span class=n>doc</span> <span class=o>=</span> <span class=n>saxReader</span><span class=o>.</span><span class=na>read</span><span class=o>(</span><span class=n>resource</span><span class=o>.</span><span class=na>getInputStream</span><span class=o>());</span>
        <span class=o>}</span> <span class=k>catch</span> <span class=o>(</span><span class=kd>final</span> <span class=n>Exception</span> <span class=n>e</span><span class=o>)</span> <span class=o>{</span>
            <span class=n>log</span><span class=o>.</span><span class=na>error</span><span class=o>(</span><span class=s>&#34;Failed to read CustomTable.hbm.xml.&#34;</span><span class=o>,</span> <span class=n>e</span><span class=o>);</span>
        <span class=o>}</span>
        <span class=kd>final</span> <span class=n>Element</span> <span class=n>rootElement</span> <span class=o>=</span> <span class=n>doc</span><span class=o>.</span><span class=na>getRootElement</span><span class=o>();</span>

        <span class=kd>final</span> <span class=n>Iterator</span><span class=o>&lt;</span><span class=n>Element</span><span class=o>&gt;</span> <span class=n>iterator</span> <span class=o>=</span> <span class=n>rootElement</span><span class=o>.</span><span class=na>elementIterator</span><span class=o>(</span><span class=s>&#34;class&#34;</span><span class=o>);</span>
        <span class=n>Element</span> <span class=n>target</span> <span class=o>=</span> <span class=kc>null</span><span class=o>;</span>
        <span class=k>while</span><span class=o>(</span><span class=n>iterator</span><span class=o>.</span><span class=na>hasNext</span><span class=o>())</span> <span class=o>{</span>
            <span class=kd>final</span> <span class=n>Element</span> <span class=n>element</span> <span class=o>=</span> <span class=n>iterator</span><span class=o>.</span><span class=na>next</span><span class=o>();</span>
            <span class=k>if</span> <span class=o>(</span><span class=n>StringUtils</span><span class=o>.</span><span class=na>equals</span><span class=o>(</span><span class=n>entityName</span><span class=o>,</span> <span class=n>element</span><span class=o>.</span><span class=na>attributeValue</span><span class=o>(</span><span class=s>&#34;entity-name&#34;</span><span class=o>,</span> <span class=n>StringUtils</span><span class=o>.</span><span class=na>EMPTY</span><span class=o>)))</span> <span class=o>{</span>
                <span class=n>target</span> <span class=o>=</span> <span class=n>element</span><span class=o>;</span>
                <span class=k>break</span><span class=o>;</span>
            <span class=o>}</span>
        <span class=o>}</span>
        <span class=k>if</span> <span class=o>(</span><span class=n>target</span> <span class=o>==</span> <span class=kc>null</span><span class=o>)</span> <span class=o>{</span>
            <span class=k>return</span> <span class=n>ctClass</span><span class=o>;</span>
        <span class=o>}</span>

        <span class=n>List</span><span class=o>&lt;</span><span class=n>Element</span><span class=o>&gt;</span> <span class=n>elements</span> <span class=o>=</span> <span class=k>new</span> <span class=n>ArrayList</span><span class=o>&lt;&gt;();</span>
        <span class=kd>final</span> <span class=n>List</span><span class=o>&lt;</span><span class=n>Element</span><span class=o>&gt;</span> <span class=n>properties</span> <span class=o>=</span> <span class=n>target</span><span class=o>.</span><span class=na>elements</span><span class=o>(</span><span class=s>&#34;property&#34;</span><span class=o>);</span>
        <span class=kd>final</span> <span class=n>List</span><span class=o>&lt;</span><span class=n>Element</span><span class=o>&gt;</span> <span class=n>components</span> <span class=o>=</span> <span class=n>target</span><span class=o>.</span><span class=na>elements</span><span class=o>(</span><span class=s>&#34;component&#34;</span><span class=o>);</span>
        <span class=n>elements</span><span class=o>.</span><span class=na>addAll</span><span class=o>(</span><span class=n>properties</span><span class=o>);</span>
        <span class=n>elements</span><span class=o>.</span><span class=na>addAll</span><span class=o>(</span><span class=n>components</span><span class=o>);</span>
        <span class=k>try</span> <span class=o>{</span>
            <span class=k>for</span> <span class=o>(</span><span class=kd>final</span> <span class=n>Element</span> <span class=n>element</span> <span class=o>:</span> <span class=n>elements</span><span class=o>)</span> <span class=o>{</span>
                <span class=n>createField</span><span class=o>(</span><span class=n>element</span><span class=o>,</span> <span class=n>ctClass</span><span class=o>);</span>
            <span class=o>}</span>
        <span class=o>}</span> <span class=k>catch</span> <span class=o>(</span><span class=kd>final</span> <span class=n>Exception</span> <span class=n>e</span><span class=o>)</span> <span class=o>{</span>
            <span class=n>log</span><span class=o>.</span><span class=na>error</span><span class=o>(</span><span class=s>&#34;Cannot create ref model.&#34;</span><span class=o>,</span> <span class=n>e</span><span class=o>);</span>
        <span class=o>}</span>

        <span class=k>return</span> <span class=n>ctClass</span><span class=o>;</span>
    <span class=o>}</span>

    <span class=kd>private</span> <span class=n>CtField</span> <span class=nf>createField</span><span class=o>(</span><span class=kd>final</span> <span class=n>Element</span> <span class=n>element</span><span class=o>,</span> <span class=kd>final</span> <span class=n>CtClass</span> <span class=n>ctClass</span><span class=o>)</span> <span class=kd>throws</span> <span class=n>NotFoundException</span><span class=o>,</span> <span class=n>CannotCompileException</span> <span class=o>{</span>
        <span class=kd>final</span> <span class=n>String</span> <span class=n>key</span> <span class=o>=</span> <span class=n>element</span><span class=o>.</span><span class=na>attributeValue</span><span class=o>(</span><span class=s>&#34;name&#34;</span><span class=o>,</span> <span class=n>StringUtils</span><span class=o>.</span><span class=na>EMPTY</span><span class=o>);</span>
		<span class=c1>// 过滤掉一些不需要的结点
</span><span class=c1></span>        <span class=k>if</span> <span class=o>(</span><span class=n>IsIgnoreElement</span><span class=o>(</span><span class=n>key</span><span class=o>))</span> <span class=o>{</span>
            <span class=k>return</span> <span class=kc>null</span><span class=o>;</span>
        <span class=o>}</span>

		<span class=c1>// 属于业务逻辑，获取到字段的类型：String、LocalDate等
</span><span class=c1></span>        <span class=kd>final</span> <span class=n>CustomFieldType</span> <span class=n>customFieldType</span> <span class=o>=</span> <span class=n>CustomFieldType</span><span class=o>.</span><span class=na>findTypeByColumnName</span><span class=o>(</span><span class=n>key</span><span class=o>).</span><span class=na>orElse</span><span class=o>(</span><span class=kc>null</span><span class=o>);</span>
        <span class=k>if</span> <span class=o>(</span><span class=n>customFieldType</span> <span class=o>==</span> <span class=kc>null</span><span class=o>)</span> <span class=o>{</span>
            <span class=k>return</span> <span class=kc>null</span><span class=o>;</span>
        <span class=o>}</span>

        <span class=n>CtClass</span> <span class=n>fieldType</span> <span class=o>=</span> <span class=kc>null</span><span class=o>;</span>
        <span class=n>CtField</span> <span class=n>ctField</span> <span class=o>=</span> <span class=kc>null</span><span class=o>;</span>
        <span class=kd>final</span> <span class=n>ClassPool</span> <span class=n>pool</span> <span class=o>=</span> <span class=n>ClassPool</span><span class=o>.</span><span class=na>getDefault</span><span class=o>();</span>
		<span class=c1>// 这里可以根据需要将字段名字替换为其他名字
</span><span class=c1></span>        <span class=kd>final</span> <span class=n>String</span> <span class=n>jsonKey</span> <span class=o>=</span> <span class=n>key</span><span class=o>;</span>

        <span class=k>switch</span> <span class=o>(</span><span class=n>customFieldType</span><span class=o>)</span> <span class=o>{</span>
        <span class=k>case</span> <span class=n>SELECTION</span><span class=o>:</span>
            <span class=n>fieldType</span> <span class=o>=</span> <span class=n>pool</span><span class=o>.</span><span class=na>get</span><span class=o>(</span><span class=n>EmbedCodelistListDemo</span><span class=o>.</span><span class=na>class</span><span class=o>.</span><span class=na>getName</span><span class=o>());</span>
            <span class=k>break</span><span class=o>;</span>
<span class=nl>
</span><span class=nl>        default:</span>
            <span class=n>fieldType</span> <span class=o>=</span> <span class=n>pool</span><span class=o>.</span><span class=na>get</span><span class=o>(</span><span class=n>customFieldType</span><span class=o>.</span><span class=na>getType</span><span class=o>().</span><span class=na>getName</span><span class=o>());</span>
            <span class=k>break</span><span class=o>;</span>
        <span class=o>}</span>

        <span class=n>ctField</span> <span class=o>=</span> <span class=k>new</span> <span class=n>CtField</span><span class=o>(</span><span class=n>fieldType</span><span class=o>,</span> <span class=n>jsonKey</span><span class=o>,</span> <span class=n>ctClass</span><span class=o>);</span>
        <span class=n>ctField</span><span class=o>.</span><span class=na>setModifiers</span><span class=o>(</span><span class=n>Modifier</span><span class=o>.</span><span class=na>PUBLIC</span><span class=o>);</span>
        <span class=n>ctClass</span><span class=o>.</span><span class=na>addField</span><span class=o>(</span><span class=n>ctField</span><span class=o>);</span>

        <span class=k>return</span> <span class=n>ctField</span><span class=o>;</span>
    <span class=o>}</span>

    <span class=kd>private</span> <span class=kt>boolean</span> <span class=nf>IsIgnoreElement</span><span class=o>(</span><span class=kd>final</span> <span class=n>String</span> <span class=n>key</span><span class=o>)</span> <span class=o>{</span>
        <span class=kt>boolean</span> <span class=n>result</span> <span class=o>=</span> <span class=kc>false</span><span class=o>;</span>
        <span class=k>switch</span> <span class=o>(</span><span class=n>key</span><span class=o>)</span> <span class=o>{</span>
        <span class=k>case</span> <span class=s>&#34;domain_id&#34;</span><span class=o>:</span>
        <span class=k>case</span> <span class=s>&#34;ref_entity_name&#34;</span><span class=o>:</span>
            <span class=n>result</span> <span class=o>=</span> <span class=kc>true</span><span class=o>;</span>
            <span class=k>break</span><span class=o>;</span>
        <span class=k>default</span><span class=o>:</span>
            <span class=k>break</span><span class=o>;</span>
        <span class=o>}</span>
        <span class=k>return</span> <span class=n>result</span><span class=o>;</span>
    <span class=o>}</span>

    <span class=c1>// Demo model
</span><span class=c1></span>    <span class=kd>static</span> <span class=kd>class</span> <span class=nc>EmbedCodelistListDemo</span> <span class=kd>extends</span> <span class=n>ArrayList</span><span class=o>&lt;</span><span class=n>EmbedCodelist</span><span class=o>&gt;</span> <span class=o>{</span>
        <span class=kd>private</span> <span class=kd>static</span> <span class=kd>final</span> <span class=kt>long</span> <span class=n>serialVersionUID</span> <span class=o>=</span> <span class=n>1L</span><span class=o>;</span>
    <span class=o>}</span>

<span class=o>}</span>
</code></pre></td></tr></table></div></div><p>这里唯一需要强调的一点是：如果Map中存在List类型的字段，比如<code>List&lt;xxDto></code>，若要在Swagger的文档中也将这个<code>xxDto</code>也显示到Example Value里，可以定义一个类，继承<code>List&lt;xxDto></code>，如上述代码中最后定义的静态内部类<code>EmbedCodelistListDemo</code>。</p><p>之所以这样实现是因为javassist来生成一个泛型List太困难（可能是我没找到正确的接口），还是直接定义这样一个类，让Java自己帮我们搞定类型来得更简单准确。</p><h2 id=按类中字段定义的顺序展示字段>按类中字段定义的顺序展示字段</h2><p>Swagger默认按照首字母顺序来显示接口和字段。</p><p>字段可以通过<code>@ApiModelProperty</code>的<code>position</code>属性来指定顺序，而接口相关的注解<code>@ApiOperation</code>则不行。但不管如何，直接靠人工添加注解来排序是不现实的；可以通过重写插件来便捷地解决这个问题。</p><p>可以通过实现ModelPropertyBuilderPlugin重写字段顺序：</p><div class=highlight><div class=chroma><table class=lntable><tr><td class=lntd><pre class=chroma><code><span class=lnt> 1
</span><span class=lnt> 2
</span><span class=lnt> 3
</span><span class=lnt> 4
</span><span class=lnt> 5
</span><span class=lnt> 6
</span><span class=lnt> 7
</span><span class=lnt> 8
</span><span class=lnt> 9
</span><span class=lnt>10
</span><span class=lnt>11
</span><span class=lnt>12
</span><span class=lnt>13
</span><span class=lnt>14
</span><span class=lnt>15
</span><span class=lnt>16
</span><span class=lnt>17
</span><span class=lnt>18
</span><span class=lnt>19
</span><span class=lnt>20
</span><span class=lnt>21
</span><span class=lnt>22
</span><span class=lnt>23
</span><span class=lnt>24
</span><span class=lnt>25
</span><span class=lnt>26
</span><span class=lnt>27
</span><span class=lnt>28
</span><span class=lnt>29
</span><span class=lnt>30
</span><span class=lnt>31
</span><span class=lnt>32
</span><span class=lnt>33
</span><span class=lnt>34
</span><span class=lnt>35
</span><span class=lnt>36
</span><span class=lnt>37
</span><span class=lnt>38
</span><span class=lnt>39
</span><span class=lnt>40
</span><span class=lnt>41
</span><span class=lnt>42
</span><span class=lnt>43
</span><span class=lnt>44
</span><span class=lnt>45
</span><span class=lnt>46
</span><span class=lnt>47
</span><span class=lnt>48
</span><span class=lnt>49
</span><span class=lnt>50
</span><span class=lnt>51
</span><span class=lnt>52
</span><span class=lnt>53
</span><span class=lnt>54
</span><span class=lnt>55
</span><span class=lnt>56
</span><span class=lnt>57
</span><span class=lnt>58
</span><span class=lnt>59
</span><span class=lnt>60
</span><span class=lnt>61
</span><span class=lnt>62
</span><span class=lnt>63
</span><span class=lnt>64
</span></code></pre></td><td class=lntd><pre class=chroma><code class=language-java data-lang=java><span class=kn>package</span> <span class=nn>test</span><span class=o>;</span>

<span class=kn>import static</span> <span class=nn>springfox.documentation.schema.Annotations.findPropertyAnnotation</span><span class=o>;</span>
<span class=kn>import static</span> <span class=nn>springfox.documentation.swagger.schema.ApiModelProperties.findApiModePropertyAnnotation</span><span class=o>;</span>

<span class=kn>import</span> <span class=nn>java.lang.reflect.Field</span><span class=o>;</span>

<span class=kn>import</span> <span class=nn>org.apache.commons.lang3.ArrayUtils</span><span class=o>;</span>
<span class=kn>import</span> <span class=nn>org.springframework.core.annotation.Order</span><span class=o>;</span>
<span class=kn>import</span> <span class=nn>org.springframework.stereotype.Component</span><span class=o>;</span>

<span class=kn>import</span> <span class=nn>com.fasterxml.jackson.databind.introspect.AnnotatedField</span><span class=o>;</span>
<span class=kn>import</span> <span class=nn>com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition</span><span class=o>;</span>
<span class=kn>import</span> <span class=nn>com.google.common.base.Optional</span><span class=o>;</span>

<span class=kn>import</span> <span class=nn>io.swagger.annotations.ApiModelProperty</span><span class=o>;</span>
<span class=kn>import</span> <span class=nn>lombok.extern.slf4j.Slf4j</span><span class=o>;</span>
<span class=kn>import</span> <span class=nn>springfox.documentation.spi.DocumentationType</span><span class=o>;</span>
<span class=kn>import</span> <span class=nn>springfox.documentation.spi.schema.ModelPropertyBuilderPlugin</span><span class=o>;</span>
<span class=kn>import</span> <span class=nn>springfox.documentation.spi.schema.contexts.ModelPropertyContext</span><span class=o>;</span>

<span class=nd>@Component</span>
<span class=nd>@Order</span>
<span class=nd>@Slf4j</span>
<span class=kd>public</span> <span class=kd>class</span> <span class=nc>CustomApiModelPropertyPositionBuilder</span> <span class=kd>implements</span> <span class=n>ModelPropertyBuilderPlugin</span> <span class=o>{</span>

    <span class=nd>@Override</span>
    <span class=kd>public</span> <span class=kt>boolean</span> <span class=nf>supports</span><span class=o>(</span><span class=kd>final</span> <span class=n>DocumentationType</span> <span class=n>delimiter</span><span class=o>)</span> <span class=o>{</span>
        <span class=k>return</span> <span class=kc>true</span><span class=o>;</span>
    <span class=o>}</span>

    <span class=nd>@Override</span>
    <span class=kd>public</span> <span class=kt>void</span> <span class=nf>apply</span><span class=o>(</span><span class=kd>final</span> <span class=n>ModelPropertyContext</span> <span class=n>context</span><span class=o>)</span> <span class=o>{</span>
        <span class=kd>final</span> <span class=n>Optional</span><span class=o>&lt;</span><span class=n>BeanPropertyDefinition</span><span class=o>&gt;</span> <span class=n>beanPropertyDefinitionOpt</span> <span class=o>=</span> <span class=n>context</span><span class=o>.</span><span class=na>getBeanPropertyDefinition</span><span class=o>();</span>
        <span class=n>Optional</span><span class=o>&lt;</span><span class=n>ApiModelProperty</span><span class=o>&gt;</span> <span class=n>annotation</span> <span class=o>=</span> <span class=n>Optional</span><span class=o>.</span><span class=na>absent</span><span class=o>();</span>
        <span class=k>if</span> <span class=o>(</span><span class=n>context</span><span class=o>.</span><span class=na>getAnnotatedElement</span><span class=o>().</span><span class=na>isPresent</span><span class=o>())</span> <span class=o>{</span>
            <span class=n>annotation</span> <span class=o>=</span> <span class=n>annotation</span><span class=o>.</span><span class=na>or</span><span class=o>(</span><span class=n>findApiModePropertyAnnotation</span><span class=o>(</span><span class=n>context</span><span class=o>.</span><span class=na>getAnnotatedElement</span><span class=o>().</span><span class=na>get</span><span class=o>()));</span>
        <span class=o>}</span>
        <span class=k>if</span> <span class=o>(</span><span class=n>context</span><span class=o>.</span><span class=na>getBeanPropertyDefinition</span><span class=o>().</span><span class=na>isPresent</span><span class=o>())</span> <span class=o>{</span>
            <span class=n>annotation</span> <span class=o>=</span> <span class=n>annotation</span><span class=o>.</span><span class=na>or</span><span class=o>(</span><span class=n>findPropertyAnnotation</span><span class=o>(</span><span class=n>context</span><span class=o>.</span><span class=na>getBeanPropertyDefinition</span><span class=o>().</span><span class=na>get</span><span class=o>(),</span> <span class=n>ApiModelProperty</span><span class=o>.</span><span class=na>class</span><span class=o>));</span>
        <span class=o>}</span>
        <span class=k>if</span> <span class=o>(</span><span class=n>beanPropertyDefinitionOpt</span><span class=o>.</span><span class=na>isPresent</span><span class=o>())</span> <span class=o>{</span>
            <span class=kd>final</span> <span class=n>BeanPropertyDefinition</span> <span class=n>beanPropertyDefinition</span> <span class=o>=</span> <span class=n>beanPropertyDefinitionOpt</span><span class=o>.</span><span class=na>get</span><span class=o>();</span>
            <span class=k>if</span> <span class=o>(</span><span class=n>annotation</span><span class=o>.</span><span class=na>isPresent</span><span class=o>()</span> <span class=o>&amp;&amp;</span> <span class=n>annotation</span><span class=o>.</span><span class=na>get</span><span class=o>().</span><span class=na>position</span><span class=o>()</span> <span class=o>!=</span> <span class=n>0</span><span class=o>)</span> <span class=o>{</span>
                <span class=k>return</span><span class=o>;</span>
            <span class=o>}</span>
            <span class=kd>final</span> <span class=n>AnnotatedField</span> <span class=n>field</span> <span class=o>=</span> <span class=n>beanPropertyDefinition</span><span class=o>.</span><span class=na>getField</span><span class=o>();</span>
            <span class=kd>final</span> <span class=n>Class</span><span class=o>&lt;?&gt;</span> <span class=n>clazz</span> <span class=o>=</span> <span class=n>field</span><span class=o>.</span><span class=na>getDeclaringClass</span><span class=o>();</span>
            <span class=kd>final</span> <span class=n>Field</span><span class=o>[]</span> <span class=n>declaredFields</span> <span class=o>=</span> <span class=n>clazz</span><span class=o>.</span><span class=na>getDeclaredFields</span><span class=o>();</span>
            <span class=n>Field</span> <span class=n>declaredField</span><span class=o>;</span>
            <span class=k>try</span> <span class=o>{</span>
                <span class=n>declaredField</span> <span class=o>=</span> <span class=n>clazz</span><span class=o>.</span><span class=na>getDeclaredField</span><span class=o>(</span><span class=n>field</span><span class=o>.</span><span class=na>getName</span><span class=o>());</span>
            <span class=o>}</span> <span class=k>catch</span> <span class=o>(</span><span class=n>NoSuchFieldException</span> <span class=o>|</span> <span class=n>SecurityException</span> <span class=n>e</span><span class=o>)</span> <span class=o>{</span>
                <span class=n>log</span><span class=o>.</span><span class=na>error</span><span class=o>(</span><span class=s>&#34;Error.&#34;</span><span class=o>,</span> <span class=n>e</span><span class=o>);</span>
                <span class=k>return</span><span class=o>;</span>
            <span class=o>}</span>
            <span class=kd>final</span> <span class=kt>int</span> <span class=n>indexOf</span> <span class=o>=</span> <span class=n>ArrayUtils</span><span class=o>.</span><span class=na>indexOf</span><span class=o>(</span><span class=n>declaredFields</span><span class=o>,</span> <span class=n>declaredField</span><span class=o>);</span>
            <span class=k>if</span> <span class=o>(</span><span class=n>indexOf</span> <span class=o>!=</span> <span class=o>-</span><span class=n>1</span><span class=o>)</span> <span class=o>{</span>
                <span class=n>context</span><span class=o>.</span><span class=na>getBuilder</span><span class=o>().</span><span class=na>position</span><span class=o>(</span><span class=n>indexOf</span><span class=o>);</span>
            <span class=o>}</span>
        <span class=o>}</span>
    <span class=o>}</span>

<span class=o>}</span>
</code></pre></td></tr></table></div></div><h2 id=参考链接>参考链接</h2><ul><li><a href=https://www.cnblogs.com/jason1990/archive/2020/03/27/12581773.html target=_blank rel="noopener noreffer">重新认识Swagger和Springfox</a></li><li><a href=https://www.cnblogs.com/jichuang/p/11733131.html target=_blank rel="noopener noreffer">Swagger2 @ApiIgnore注解忽略接口在swagger-ui.html中显示</a></li><li><a href=https://blog.csdn.net/hhjyan/article/details/117229253 target=_blank rel="noopener noreffer">spring boot集成swagger之springfox-boot-starter配置指定paths()（四）</a></li><li><a href=https://www.jianshu.com/p/c91591843770 target=_blank rel="noopener noreffer">swagger扩展为按代码定义顺序展示接口和字段</a></li></ul><div class="details admonition warning open"><div class="details-summary admonition-title"><i class="icon fas fa-exclamation-triangle fa-fwwarning"></i>警告<i class="details-icon fas fa-angle-right fa-fw"></i></div><div class=details-content><div class=admonition-content>本文最后更新于 <span class=timeago datetime=2021-09-01T23:49:08 title="September 1, 2021">September 1, 2021</span>，文中内容可能已过时，请谨慎使用。</div></div></div><div class=post-reward><input type=checkbox name=reward id=reward hidden>
<label class=reward-button for=reward>赞赏支持</label><div class=qr-code><label class=qr-code-image for=reward><img class=image src=https://cdn.jsdelivr.net/gh/lewky/lewky.github.io@master/images/common/wechat.png>
<span>微信打赏</span></label>
<label class=qr-code-image for=reward><img class=image src=https://cdn.jsdelivr.net/gh/lewky/lewky.github.io@master/images/common/alipay.png>
<span>支付宝打赏</span></label></div></div></div><div class=post-footer id=post-footer><div class=post-info><div class=post-info-line><div class=post-info-mod><span>更新于 2021-09-01</span></div><div class=post-info-license><span><a rel="license external nofollow noopener noreffer" href=https://creativecommons.org/licenses/by-nc/4.0/ target=_blank>CC BY-NC 4.0</a></span></div></div><div class=post-info-line><div class=post-info-md><span><a class=link-to-markdown href=/posts/swagger-issues/index.md target=_blank>阅读原始文档</a></span></div><div class=post-info-share><span><a href=javascript:void(0); title="分享到 Twitter" data-sharer=twitter data-url=https://lewky.cn/posts/swagger-issues/ data-title=Swagger问题汇总 data-hashtags=Swagger,SpringFox,工作记录><i class="fab fa-twitter fa-fw"></i></a><a href=javascript:void(0); title="分享到 Facebook" data-sharer=facebook data-url=https://lewky.cn/posts/swagger-issues/ data-hashtag=Swagger><i class="fab fa-facebook-square fa-fw"></i></a><a href=javascript:void(0); title="分享到 Hacker News" data-sharer=hackernews data-url=https://lewky.cn/posts/swagger-issues/ data-title=Swagger问题汇总><i class="fab fa-hacker-news fa-fw"></i></a><a href=javascript:void(0); title="分享到 Line" data-sharer=line data-url=https://lewky.cn/posts/swagger-issues/ data-title=Swagger问题汇总><i data-svg-src=https://cdn.jsdelivr.net/npm/simple-icons@2.14.0/icons/line.svg></i></a><a href=javascript:void(0); title="分享到 微博" data-sharer=weibo data-url=https://lewky.cn/posts/swagger-issues/ data-title=Swagger问题汇总><i class="fab fa-weibo fa-fw"></i></a></span></div></div></div><div class=post-info-more><section class=post-tags><i class="fas fa-tags fa-fw"></i>&nbsp;<a href=/tags/swagger/>Swagger</a>,&nbsp;<a href=/tags/springfox/>SpringFox</a>,&nbsp;<a href=/tags/%E5%B7%A5%E4%BD%9C%E8%AE%B0%E5%BD%95/>工作记录</a></section><section><span><a href=javascript:void(0); onclick=window.history.back();>返回</a></span>&nbsp;|&nbsp;<span><a href=/>主页</a></span></section></div><div class=post-nav><a href=/posts/java-tree.html/ class=prev rel=prev title="Java - 数据结构之树"><i class="fas fa-angle-left fa-fw"></i>Java - 数据结构之树</a>
<a href=/posts/maven-issues/ class=next rel=next title=Maven问题汇总>Maven问题汇总<i class="fas fa-angle-right fa-fw"></i></a></div></div><div id=comments><div id=waline></div><script src=https://cdn.jsdelivr.net/npm/@waline/client/dist/Waline.min.js></script><script>new Waline({el:'#waline',meta:["nick","mail","link"],requiredMeta:["nick","mail"],login:"force",placeholder:"为防恶意灌水攻击，评论前需注册并登录，望见谅~",serverURL:"https://comment.lewky.cn/",avatarCDN:"https://sdn.geekzu.org/avatar/",pageSize:20,avatar:"retro",lang:"zh-CN",visitor:true,highlight:true,uploadImage:false,emoji:['https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/emoji/嘉然今天吃什么','https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/emoji/大航海嘉然','https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/emoji/向晚大魔王','https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/emoji/贝拉kira','https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/emoji/珈乐Carol','https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/emoji/乃琳Queen','https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/emoji/EveOneCat','https://cdn.jsdelivr.net/gh/walinejs/emojis@1.0.0/weibo','https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/emoji/滑稽','https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/emoji/default']});</script></div></article></div></main><footer class=footer><div class=footer-container><div class=footer-line><span id=run-time></span>|
<a href=http://rssblog.vercel.app/ target=_blank rel=noopener title=RSSBlog><i class="fas fa-fw fa-inbox"></i>&nbsp;RSSBlog</a></div><div class=footer-line><i class="far fa-copyright fa-fw"></i><span itemprop=copyrightYear>2018 - 2022</span><span class=author itemprop=copyrightHolder>&nbsp;<a href=/ target=_blank>雨临Lewis</a></span>&nbsp;|&nbsp;<span class=license><a rel="license external nofollow noopener noreffer" href=https://creativecommons.org/licenses/by-nc/4.0/ target=_blank>CC BY-NC 4.0</a></span><span class=icp-splitter>&nbsp;|&nbsp;</span><br class=icp-br><span class=icp><a target=_blank href=http://www.beian.miit.gov.cn/ style=font-weight:700>粤ICP备19103822</a></span></div></div></footer></div><div id=fixed-buttons><a href=# id=back-to-top class=fixed-button title=回到顶部><i class="fas fa-arrow-up fa-fw"></i></a><a href=# id=view-comments class=fixed-button title=查看评论><i class="fas fa-comment fa-fw"></i></a></div><div class=sidebar_wo><div id=leimu><img src=https://cdn.jsdelivr.net/gh/lewky/lewky.github.io@master/images/b2t/leimuA.png alt=雷姆 onmouseover="this.src='https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/b2t/leimuB.png'" onmouseout="this.src='https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/b2t/leimuA.png'" title=回到顶部></div><div class=sidebar_wo id=lamu><img src=https://cdn.jsdelivr.net/gh/lewky/lewky.github.io@master/images/b2t/lamuA.png alt=雷姆 onmouseover="this.src='https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/b2t/lamuB.png'" onmouseout="this.src='https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/b2t/lamuA.png'" title=回到底部></div></div><link rel=stylesheet href=https://cdn.jsdelivr.net/npm/lightgallery.js@1.2.0/dist/css/lightgallery.min.css><script type=text/javascript src=https://cdn.jsdelivr.net/npm/smooth-scroll@16.1.3/dist/smooth-scroll.min.js></script><script type=text/javascript src=https://cdn.jsdelivr.net/npm/lazysizes@5.2.2/lazysizes.min.js></script><script type=text/javascript src=https://cdn.jsdelivr.net/npm/lightgallery.js@1.2.0/dist/js/lightgallery.min.js></script><script type=text/javascript src=https://cdn.jsdelivr.net/npm/lg-thumbnail.js@1.2.0/dist/lg-thumbnail.min.js></script><script type=text/javascript src=https://cdn.jsdelivr.net/npm/lg-zoom.js@1.2.0/dist/lg-zoom.min.js></script><script type=text/javascript src=https://cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js></script><script type=text/javascript src=https://cdn.jsdelivr.net/npm/sharer.js@0.4.0/sharer.min.js></script><script type=text/javascript>window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":30},"comment":{},"lightGallery":{"actualSize":false,"exThumbImage":"data-thumbnail","hideBarsDelay":2000,"selector":".lightgallery","speed":400,"thumbContHeight":80,"thumbWidth":80,"thumbnail":true}};</script><script type=text/javascript src=/js/theme.min.js></script><script type=text/javascript src=https://cdn.jsdelivr.net/npm/jquery@2.1.3/dist/jquery.min.js></script><script type=text/javascript src=https://cdn.jsdelivr.net/npm/jquery-backstretch@2.1.18/jquery.backstretch.min.js></script><script>var $cdnPrefix="https://cdn.jsdelivr.net/gh/lewky/lewky.github.io@master";</script><script type=text/javascript src=/js/custom.js></script><script>var _hmt=_hmt||[];(function(){var hm=document.createElement("script");hm.src="https://hm.baidu.com/hm.js?6f278ed0fdb01edb3b1e7398379e5432";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(hm,s);})();</script></body></html>